package cn.getech.data.development.controller;

import java.util.List;

import cn.getech.data.development.model.req.procjobstatistics.ProcJobStatisticsCompleteReq;
import cn.getech.data.development.model.req.procjobstatistics.ProcJobStatisticsGetLastReq;
import cn.getech.data.development.model.res.procjobstatistics.OfflineDurationTop20Res;
import cn.getech.data.development.model.res.procjobstatistics.ProcJobStatisticsRes;
import cn.getech.data.development.model.res.procjobstatistics.CompleteStatisticsRes;
import cn.getech.data.intelligence.common.utils.*;
import cn.getech.data.intelligence.common.validator.group.AddGroup;
import cn.getech.system.center.annotation.SysLog;
import cn.getech.system.center.constant.OperationModulesEnum;
import cn.getech.system.center.constant.OperationTypeEnum;
import cn.getech.system.center.constant.module.ModuleEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.getech.data.development.service.ProcJobStatisticsService;
import cn.getech.data.intelligence.common.validator.ValidatorUtils;


/**
 * 项目任务运行统计
 *
 * @author qiuxinglei
 * @email qiuxinglei@gmail.com
 * @date 2020-09-04 15:45:42
 */
@Api(value="项目任务运行统计",tags={"项目任务运行统计"})
@RestController
@RequestMapping("development/procjobstatistics")
public class ProcJobStatisticsController {
    @Autowired
    private ProcJobStatisticsService procJobStatisticsService;

    @ApiOperation("获取最新统计项目数(项目数、运行、失败)")
    @PostMapping("/getLastHourStatistics")
    @SysLog(value="获取最新统计项目数(项目数、运行、失败)",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<ProcJobStatisticsRes> getLastHourStatistics(@RequestBody ProcJobStatisticsGetLastReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        ProcJobStatisticsRes resObj = procJobStatisticsService.getLast(req);

        return BaseRes.okWithData(resObj);
    }

    @ApiOperation("本周离线任务执行率")
    @PostMapping("/offlineWeekRateOfSuccess")
    @SysLog(value="本周离线任务执行率",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<List<NameValue<Integer>>> offlineWeekRateOfSuccess(@RequestBody ProcJobStatisticsGetLastReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        List<NameValue<Integer>> resObj = procJobStatisticsService.offlineWeekRateOfSuccess(req);

        return BaseRes.okWithData(resObj);
    }

    @ApiOperation("本周离线运行状态分布")
    @PostMapping("/offlineRunState")
    @SysLog(value="本周离线运行状态分布",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<List<NameValue<Integer>>> offlineRunState(@RequestBody ProcJobStatisticsGetLastReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        List<NameValue<Integer>> resObj = procJobStatisticsService.offlineRunState(req);

        return BaseRes.okWithData(resObj);
    }

    @ApiOperation("离线任务完成情况")
    @PostMapping("/offlineComplete")
    @SysLog(value="离线任务完成情况",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<CompleteStatisticsRes> offlineComplete(@RequestBody ProcJobStatisticsCompleteReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        CompleteStatisticsRes resObj = procJobStatisticsService.complete(req, true);

        return BaseRes.okWithData(resObj);
    }

    @ApiOperation("离线任务执行时长排行top20")
    @PostMapping("/offlineDurationTop20")
    @SysLog(value="离线任务执行时长排行top20",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<List<OfflineDurationTop20Res>> offlineDurationTop20(@RequestBody ProcJobStatisticsCompleteReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        List<OfflineDurationTop20Res> resList = procJobStatisticsService.offlineDurationTop20(req);

        return BaseRes.okWithData(resList);
    }

    @ApiOperation("实时任务完成情况")
    @PostMapping("/realtimeComplete")
    @SysLog(value="实时任务完成情况",type= OperationTypeEnum.SELECTCODE, modulesType = OperationModulesEnum.BDPMODELCODE,platformModuleType = ModuleEnum.DATA_VIEW_MODULE_CODE)
    public DataRes<CompleteStatisticsRes> realtimeComplete(@RequestBody ProcJobStatisticsCompleteReq req){
        ValidatorUtils.validateEntity(req, AddGroup.class);
        CompleteStatisticsRes resObj = procJobStatisticsService.complete(req, false);

        return BaseRes.okWithData(resObj);
    }
}
